package com.adv.ems.controller.admin;

import com.adv.ems.constants.SystemConst;
import com.adv.ems.model.dto.APIRequest;
import com.adv.ems.model.dto.APIResponse;
import com.adv.ems.model.param.BaseDiagramInfoParam;
import com.adv.ems.model.param.BaseDiagramRelateRelationDelVO;
import com.adv.ems.model.vo.BaseDiagramRelateAddVO;
import com.adv.ems.model.vo.BaseDiagramRelateListVO;
import com.adv.ems.service.BaseDataService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@RestController
@RequestMapping("/ems/client/base/diagram")
public class CircuitDiagramNodeController {
    @Resource
    BaseDataService baseDataService;

    @PostMapping("/update")
    public APIResponse<Boolean> update(@RequestHeader(name = SystemConst.Header.ACCEPT_LANGUAGE, defaultValue = SystemConst.Header.ZH_CN) String acceptLanguage,
                                       @RequestBody APIRequest<BaseDiagramInfoParam> request) {
        return APIResponse.<Boolean>build().content(baseDataService.diagramUpdate(request.getContent(), acceptLanguage));
    }

    @PostMapping("/delete")
    public APIResponse<Boolean> delete(@RequestHeader(name = SystemConst.Header.ACCEPT_LANGUAGE, defaultValue = SystemConst.Header.ZH_CN) String acceptLanguage,
                                       @RequestBody APIRequest<Long> request) {
        return APIResponse.<Boolean>build().content(baseDataService.diagramDelete(request.getContent(), acceptLanguage));
    }

    @PostMapping("/relate/list")
    public APIResponse<BaseDiagramRelateListVO> relateList(@RequestHeader(name = SystemConst.Header.ACCEPT_LANGUAGE, defaultValue = SystemConst.Header.ZH_CN) String acceptLanguage,
                                                           @RequestBody APIRequest<Long> request) {
        return APIResponse.<BaseDiagramRelateListVO>build().content(baseDataService.relateList(request.getContent(), acceptLanguage));
    }

    @PostMapping("/relate/add")
    public APIResponse<Boolean> relateAdd(@RequestHeader(name = SystemConst.Header.ACCEPT_LANGUAGE, defaultValue = SystemConst.Header.ZH_CN) String acceptLanguage,
                                                           @RequestBody APIRequest<BaseDiagramRelateAddVO> request) {
        return APIResponse.<Boolean>build().content(baseDataService.relateAdd(request.getContent(), acceptLanguage));
    }

    @PostMapping("/relate/delete")
    public APIResponse<Boolean> relateDelete(@RequestHeader(name = SystemConst.Header.ACCEPT_LANGUAGE, defaultValue = SystemConst.Header.ZH_CN) String acceptLanguage,
                                          @RequestBody APIRequest<BaseDiagramRelateRelationDelVO> request) {
        return APIResponse.<Boolean>build().content(baseDataService.relateDelete(request.getContent(), acceptLanguage));
    }
}
